 <link rel="stylesheet" type="text/css" href="css/style.css">
<?php

$nome = $_GET['nome'];
$codfis=$_GET['codfis'];
$piva = $_GET['piva'];
$pratica = $_GET['pratica'];

require_once("db_connect.inc");

$query = "SELECT *
		FROM finanziamento as A, persona_fisica as B, persona_giuridica as C
		WHERE  (A.persona_fisica = B.codice_fiscale OR A.persona_giuridica=C.partita_IVA)
		AND (";
if($piva) {
    $query.= "(B.partita_IVA = '$piva' OR C.partita_IVA='$piva') OR";
}
if($nome)
    $query.= "(B.denominazione = '$nome' OR C.denominazione='$nome') OR";
if($codfis)
    $query.= "(B.codice_fiscale = '$codfis' OR C.codice_fiscale='$codfis') OR";
if($pratica)
    $query.= "(A.codice = '$pratica'));";

$l = strlen($query);
if($query[$l-1]=="R" && $query[$l-2]=="O" && $query[$l-3]==" ")
{   
    
    $query[$l-3]=")";
    
    $query[$l-2]=";";
    $query[$l-1]="";
}

$query.=";";

$res = mysql_query($query)  or die(mysql_error());
?>
<table class="tabellaResult">
    <tr class="intestazione">
        <td></td>
        <td></td>
        <td>Numero pratica</td>
        <td>Tipo prodotto</td>
        <td>Data Creazione</td>
        <td>Impresa</td>
        <td>Operatore</td>
        <td>Stato</td>
        <td>Importo</td>
    </tr>


<?php
$x = 0;
while($ris = mysql_fetch_array($res)) {
    echo "<tr>
            <td><a href='modifica.php?pratica=".$ris[0]."'><img src='img/lente.jpg' width=30 height=30></a></td>
            <td><a href='cancella.php?pratica=".$ris[0]."'><img src='img/cestino.png'  width=30 height=30></a></td>
            <td>".$ris[0]."</td>
            <td>".$ris[3]."</td>
            <td>".$ris[14]."</td>
            <td>".$ris[17]."</td>
            <td>".$ris[12]."</td>
            <td>".$ris[4]."</td>
            <td>".$ris[1]."</td>
         </tr>";
    $x++;
}
if($x==0){
    echo "<tr><td colspan=9 align=center> Nessuna pratica corrispondente alle chiavi di ricerca </td></tr>";
}
?>
</table>
